<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="用户名称" prop="userId">
    <!-- <el-input v-model="dataForm.userId" placeholder="用户主键"></el-input> -->
     <el-select v-model="dataForm.userId" placeholder="请选择用户名称">
            <el-option
              v-for="item in userList"
              :key="item.id"
              :label="item.userUsername"
              :value="item.id">
            </el-option>
          </el-select>
    </el-form-item>
    <el-form-item label="投诉内容" prop="content">
      <el-input v-model="dataForm.content" placeholder="投诉内容"></el-input>
    </el-form-item>
    <el-form-item label="投诉时间" prop="complaintTime">
    <!-- <el-input v-model="dataForm.complaintTime" placeholder="投诉时间"></el-input>-->

      <el-date-picker
              v-model="dataForm.complaintTime"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="datetime"
              placeholder="选择抄表时间">
            </el-date-picker>
    </el-form-item>
    <el-form-item label="处理时间" prop="disposeTime">
    <!--  <el-input v-model="dataForm.disposeTime" placeholder="处理时间"></el-input> -->

       <el-date-picker
            v-model="dataForm.disposeTime"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
            placeholder="选择抄表时间">
          </el-date-picker>
    </el-form-item>
    <el-form-item label="状态(1： 待处理 2: 已解决 3. 未解决 4. 已撤销 )" prop="state">
      <el-input v-model="dataForm.state" placeholder="状态(1： 待处理 2: 已解决 3. 未解决 4. 已撤销 )"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          userId: '',
          content: '',
          complaintTime: '',
          disposeTime: '',
          state: ''
        },
        userList: [],
        dataRule: {
          userId: [
            { required: true, message: '用户主键不能为空', trigger: 'blur' }
          ],
          content: [
            { required: true, message: '投诉内容不能为空', trigger: 'blur' }
          ],
          complaintTime: [
            { required: true, message: '投诉时间不能为空', trigger: 'blur' }
          ],
          disposeTime: [
            { required: true, message: '处理时间不能为空', trigger: 'blur' }
          ],
          state: [
            { required: true, message: '状态(1： 待处理 2: 已解决 3. 未解决 4. 已撤销 )不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    created () {
      this.getAllList()
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/use/appcomplaint/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.userId = data.appComplaint.userId
                this.dataForm.content = data.appComplaint.content
                this.dataForm.complaintTime = data.appComplaint.complaintTime
                this.dataForm.disposeTime = data.appComplaint.disposeTime
                this.dataForm.state = data.appComplaint.state
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/use/appcomplaint/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'userId': this.dataForm.userId,
                'content': this.dataForm.content,
                'complaintTime': this.dataForm.complaintTime,
                'disposeTime': this.dataForm.disposeTime,
                'state': this.dataForm.state
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      },
 // 获取用户下拉框
      getAllList () {
        this.$http({
          url: this.$http.adornUrl('/use/appuser/listAll'),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.userList = data.list
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      }
    }
  }
</script>
